<template>
  <div class='report-alert'>
    <div v-transfer-dom>
      <popup v-model="$store.state.dialogs.reportalert.show">
        <div class="box report-model">
          <p class="clear btn-box">
            <span class="fl btn-active" @click="cancelThis"> 取消</span>
            <span class="fr sure btn-active" @click="$store.state.dialogs.reportalert.show=false">确定</span>
          </p>
          <p class="title-box pr">
            <span class="line"></span>
            <span class="dot"></span>
            <span class="title">检测详细</span>
            <span class="dot"></span>
            <span class="line"></span>
          </p>
          <Form :formData="formData" :formParam="alertParams"></Form>
        </div>
      </popup>
    </div>
    <input name="upload_file" style="display:none" id="camera" ref="camera" type="file" accept="image/*" capture="camera" @change="choosePic">
  </div>
</template>
<script>
import { Popup, TransferDom } from "vux";
import Form from "../../common/form";
export default {
  props: ["alertParams"],
  directives: {
    TransferDom
  },
  components: { Popup, Form },
  name: "",
  data() {
    return {
      actionUrl: PATH + "store/uploadPictures.do",
      formData: [
        {
          title: {
            show: false
          },
          children: [
            {
              type: "input",
              label: "检测项目",
              key: "detectionName",
              readonly: true
            },
            {
              type: "radio",
              label: "项目状态",
              key: "detectionStatus",
              carstate: true,
              array: [
                { label: "良好", key: "1" },
                { label: "轻微", key: "2" },
                { label: "严重", key: "3" }
              ]
            },
            {
              type: "radio",
              label: "建议操作",
              key: "advice",
              carstate: true,
              array: [
                { label: "保养", key: "1" },
                { label: "维修", key: "2" },
                { label: "换新", key: "3" }
              ]
            },
            {
              type: "number",
              label: "费用估计",
              placeholder: "请输入预估费用",
              key: "price"
            },
            { type: "switch", label: "客户是否维修", key: "isService" },
            { type: "input", label: "维修状态", key: "serviceStatus" },
            {
              type: "input",
              label: "检测图片",
              placeholder:"  ",
              camera: true,
              textClick: this.openCamera,
              readonly: true
            },
            {
              type: "imgs",
              key: "picture",
            },
            { type: "number", label: "下次提醒天数",paddingLeft10:true, key: "days" }
          ]
        }
      ]
    };
  },
  methods: {
    openCamera() {
      this.$refs.camera.click();
    },
    cancelThis() {
      this.$store.state.dialogs.reportalert.show=false
      // 取消重置数据
      this.alertParams.detectionStatus=1
      this.alertParams.advice=1
      this.alertParams.price=""
      this.alertParams.isService=false
      this.alertParams.serviceStatus=""
      this.alertParams.picture=[]
      this.alertParams.days=""
    },

    choosePic(val) {
      var that=this
      var file=val.target.files[0]
      var length=this.alertParams.picture
      var reader = new FileReader();
      reader.onload = function(){
        that.alertParams.picture.push(reader.result)
      }
      reader.readAsDataURL(file);

      _store.state.dialogs.loading.show=true
      var data = new FormData();
      data.append("upload_file", file);
      this.axios.post(PATH+"store/uploadPictures.do",data, {
        headers: {
          "Content-Type": "multipart/form-data"
        }
      }).then(res=>{
        _store.state.dialogs.loading.show=false
        this.alertParams.picture.splice(length,1,res.data.data)
      })

      // $.ajax({
      //   type: "post",
      //   url:PATH+"store/uploadPictures.do",
      //   dataType: "json",
      //   data,
      //   headers: { 'contentType': 'application/x-www-form-urlencoded' },
      //   success:function(data){
      //     console.log(data)
      //   }
      // })
    }
  },
  created() {}
};
</script>
<style lang="scss" scoped>
.report-alert {
}
.box {
  text-align: center;
  padding: 15px 0;
  background-color: #fff;

  .btn-box {
    padding: 0 15px;
    font-size: 14px;

    span {
      border: 1px solid #bfbfbf;
      color: #999;
      width: 40px;
      height: 20px;
      line-height: 20px;
      box-sizing: border-box;
      text-align: center;
      border-radius: 12px;
    }
    .sure {
      background-color: #ff9f20;
      color: #fff;
      border-color: #ff9f20;
    }
  }

  .title-box {
    margin-bottom: 20px;

    .dot {
      display: inline-block;
      width: 0;
      padding: 3px;
      border-radius: 50%;
      background-color: #fc9522;
      transform: translateY(-2px);
    }
    .line {
      display: inline-block;
      width: 50px;
      height: 1px;
      background-color: #fc9522;
      transform: translateY(-4px);
    }
  }
}
</style>